package org.streets.eis.component.datetime;

import java.sql.Timestamp;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.string.Strings;

public class DateTimeField  extends TextField<Timestamp>{
	private static final long serialVersionUID = 1L;

	public DateTimeField(String id, IModel<Timestamp> model){
		super(id,model,Timestamp.class);
		add(new DatePickerBehavior());
	}
	
	@Override
	protected void onComponentTag(ComponentTag tag){
		checkComponentTag(tag, "input");
		if (tag.getAttributes().containsKey("type")){
			checkComponentTagAttribute(tag, "type", "text");
		} else {
			tag.put("type", "text");
		}
		String title = tag.getAttribute("title");
		if (Strings.isEmpty(title)){
			tag.put("title", "(日期时间格式：yyyy-MM-dd HH:mm:ss)");
		} else {
			tag.put("title", "(日期时间格式：yyyy-MM-dd HH:mm:ss)" +"\r\n" + title);
		}	
		
		super.onComponentTag(tag);
	}
	
}
